const ws = new webSocket("ws://localhost:8000"); //连接客户端

//上线
ws.onopen = () => {
    ws.send("我上线了"); //发送消息给服务器
};

//发送信息 message事件
ws.onmessage = msg => {
    console.log(msg);
    const content = document.getElementById("content"); //拿到id为content的dom对象
    //用这个dom对象动态的增加一些数据
    content.innerHTML += msg.data + "<br>"
};


//报错
ws.onerror = () => {
    console.log(err);
};

//下线
ws.onclose = () => {
    console.log("下线了");
};